import scala.util.parsing.combinator.syntactical.StandardTokenParsers
import scala.collection.immutable.HashMap

package parser
{
	object AttributeParser extends StandardTokenParsers  
	{
	  	  protected val attTypes : HashMap[String, String => AnyRef] =   
  			  						HashMap( "label" -> asString,
	  			  							 "image" -> asString,
						  				 	 "checked" -> asBoolean, 
						  				 	 "value" -> asInteger,
						  				 	 "enabled" -> asBoolean,
						  				 	 "fgcolor" -> asInteger,
						  				 	 "bgcolor" -> asInteger,
						  				 	 "font" -> asFontTup,
						  				 	 "halign" -> ashalign,
						  				 	 "valign" -> asvalign,
						  				 	 "minvalue" -> asInteger,
						  				 	 "maxvalue" -> asInteger);

	  	  // parsing different types of values
	  	  protected def asString(value : String) : AnyRef = value.asInstanceOf[AnyRef];
	  	  protected def asInteger(value :String) : AnyRef = value.toInt.asInstanceOf[AnyRef];
	  	  protected def asBoolean(value : String) : AnyRef = value.toBoolean.asInstanceOf[AnyRef];
	  	  protected def ashalign(value : String) : AnyRef = 
	  	  {
	  	    if (value == "left")
	  	      return 0.asInstanceOf[AnyRef];
	  	    else if (value == "center")
	  	      return 1.asInstanceOf[AnyRef];
	  	    else if (value == "right")
	  	      return 2.asInstanceOf[AnyRef];
	  	    else
	  	      // error input
	  	      return -1.asInstanceOf[AnyRef];
	  	  }
  	  	  protected def asvalign(value : String) : AnyRef =
	  	  {
	  	    if (value == "top")
	  	      return 0.asInstanceOf[AnyRef];
	  	    else if (value == "middle")
	  	      return 1.asInstanceOf[AnyRef];
	  	    else if (value == "bottom")
	  	      return 2.asInstanceOf[AnyRef];
	  	    else
	  	      // error input
	  	      return -1.asInstanceOf[AnyRef];
	  	  }
  	  	  protected def asFontTup(value : String) : AnyRef = 
  	  	  {
  	  	    val values = value.drop(1).dropRight(1).split(",")
  	  	    return (values(0), values(1).toInt, values(2)).asInstanceOf[AnyRef];
  	  	  }
  	  	  
	  	  def attValType(attName : String, attVal : String) : AnyRef =
	  	  {
  			  return attTypes(attName)(attVal).asInstanceOf[AnyRef];
	  	  }
	  	  	  	  	  	  
	}
}